﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using CRM.Entity;

using CRM.BLL;
using DP.Web.UI.Controls;
using DP.Web.UI;
using DP.Common;
using System.Data;


namespace CRM.Web.ConsultingCaseManage
{
    public partial class List :Common.PageBase
    {

        public string ModifyUrl = "Modify.aspx?CASEID={0}";
        T_CONSULTINGCASE_BLL bll = new T_CONSULTINGCASE_BLL();
        private T_CONTENTAUTHORITY_BLL caBll = new T_CONTENTAUTHORITY_BLL();
        private T_WORKORDERSTATUS_BLL workOrderStatusBll = new T_WORKORDERSTATUS_BLL();
        T_DICTIONARY_BLL dBll = new T_DICTIONARY_BLL();

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            gvList.PageSize = StringHelper.ToInt(configBll.GetCacheValueByName(this.Page, "PageSize"), 20);
            PageHelper.SetPopCalender(this.Page, txtCREATETIMEBegin);
            PageHelper.SetPopCalender(this.Page, txtCREATETIMEEnd);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblExportMaxRows.Text = configBll.GetCacheValueByName(this.Page, "ExportMaxRows");
                txtRecordBegin.Text = StaticConstant.RecordBegin;
                txtRecordEnd.Text = StaticConstant.RecordEnd;
                ddlExtendedBinding();
                ddlSTATUSBinding();
                ddlCONSULTINGTYPEBinding();


                GetUrlQueryToControl();
                gvDataBinding();
            }
        }

        #region 页面初始化数据绑定

        /// <summary>
        /// DDLs the extended binding.
        /// </summary>
        private void ddlExtendedBinding()
        {
            EnumHelper.FillListControl(ddlExtended, typeof(CaseExtended));
            ddlExtended.Items.Insert(0, new ListItem("", ""));
        }


        /// <summary>
        /// DDLs the STATUS binding.
        /// </summary>
        private void ddlSTATUSBinding()
        {

            ddlSTATUS.DataSource =
                workOrderStatusBll.GetList(String.Format(" and OrderTypeID = '{0}' ",
                                                         ((int) WorkOrderType.咨询工单).ToString()));

            ddlSTATUS.DataTextField = "ORDERSTATUSNAME";
            ddlSTATUS.DataValueField = "ORDERSTATUSID";
            ddlSTATUS.DataBind();
            ddlSTATUS.Items.Insert(0, new ListItem("", ""));
        }


        private void ddlCONSULTINGTYPEBinding()
        {
            ddlCONSULTINGTYPE.DataSource = dBll.GetCacheListByType(this.Page, DictionaryType.GetNameByKey("ConsultingType"));
            ddlCONSULTINGTYPE.DataTextField = "DictValue";
            ddlCONSULTINGTYPE.DataValueField = "DictKey";
            ddlCONSULTINGTYPE.DataBind();
            ddlCONSULTINGTYPE.Items.Insert(0, new ListItem("", ""));

        }


        #endregion

        /// <summary>
        /// 获取 URL 上的参数存入当页面 控件中。
        /// </summary>
        private void GetUrlQueryToControl()
        {
            PageHelper.GetUrlQueryToControl(this.Page);
        }

        /// <summary>
        /// 生成查询条件字符串
        /// </summary>
        /// <returns></returns>
        private StringBuilder GenerationSQLString()
        {
            StringBuilder sql = new StringBuilder();
            #region MyRegion
            if (!String.IsNullOrEmpty(Request.QueryString["CASEID"]))
            {
                sql.Append(" and CASEID like '%" + Request.QueryString["CASEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLER"]))
            {
                sql.Append(" and CALLER like '%" + Request.QueryString["CALLER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLED"]))
            {
                sql.Append(" and CALLED like '%" + Request.QueryString["CALLED"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLID"]))
            {
                sql.Append(" and CALLID = '" + Request.QueryString["CALLID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECORDCODE"]))
            {
                sql.Append(" and RECORDCODE like '%" + Request.QueryString["RECORDCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLTYPE"]))
            {
                sql.Append(" and CALLTYPE like '%" + Request.QueryString["CALLTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERID"]))
            {
                sql.Append(" and CUSTOMERID = '" + Request.QueryString["CUSTOMERID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERNAME"]))
            {
                sql.Append(" and CUSTOMERNAME like '%" + Request.QueryString["CUSTOMERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTCONTACTTEL"]))
            {
                sql.Append(" and FIRSTCONTACTTEL like '%" + Request.QueryString["FIRSTCONTACTTEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ADDRESS"]))
            {
                sql.Append(" and ADDRESS like '%" + Request.QueryString["ADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COUNTRY"]))
            {
                sql.Append(" and COUNTRY like '%" + Request.QueryString["COUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROVINCE"]))
            {
                sql.Append(" and PROVINCE like '%" + Request.QueryString["PROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PREFECTURECITY"]))
            {
                sql.Append(" and PREFECTURECITY like '%" + Request.QueryString["PREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CITY"]))
            {
                sql.Append(" and CITY like '%" + Request.QueryString["CITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGETOWN"]))
            {
                sql.Append(" and VILLAGETOWN like '%" + Request.QueryString["VILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGE"]))
            {
                sql.Append(" and VILLAGE like '%" + Request.QueryString["VILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GROUPTEAM"]))
            {
                sql.Append(" and GROUPTEAM like '%" + Request.QueryString["GROUPTEAM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONSULTINGTYPE"]))
            {
                sql.Append(" and CONSULTINGTYPE like '%" + Request.QueryString["CONSULTINGTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VINCODE"]))
            {
                sql.Append(" and upper(VINCODE) like '%" + Request.QueryString["VINCODE"].ToUpper() + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRAND"]))
            {
                sql.Append(" and BRAND like '%" + Request.QueryString["BRAND"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPE"]))
            {
                sql.Append(" and VEHICLETYPE like '%" + Request.QueryString["VEHICLETYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTCODE"]))
            {
                sql.Append(" and PRODUCTCODE like '%" + Request.QueryString["PRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIES"]))
            {
                sql.Append(" and SERIES like '%" + Request.QueryString["SERIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELS"]))
            {
                sql.Append(" and MODELS like '%" + Request.QueryString["MODELS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODEL"]))
            {
                sql.Append(" and ENGINEMODEL like '%" + Request.QueryString["ENGINEMODEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERS"]))
            {
                sql.Append(" and ENGINEMANUFACTURERS like '%" + Request.QueryString["ENGINEMANUFACTURERS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CONSULTINGCONTENT"]))
            {
                sql.Append(" and CONSULTINGCONTENT like '%" + Request.QueryString["CONSULTINGCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["APPROACH"]))
            {
                sql.Append(" and APPROACH like '%" + Request.QueryString["APPROACH"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATUS"]))
            {
                sql.Append(" and STATUS = '" + Request.QueryString["STATUS"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RESULTS"]))
            {
                sql.Append(" and RESULTS like '%" + Request.QueryString["RESULTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMINDERTIME"]))
            {
                sql.Append(" and REMINDERTIME like '%" + Request.QueryString["REMINDERTIME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEBegin"]))
            {
                sql.Append(" and  " + bll._dal.GetBeginDateString("CREATETIME", Request.QueryString["CREATETIMEBegin"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEEnd"]))
            {
                sql.Append(" and  " + bll._dal.GetEndDateString("CREATETIME", Request.QueryString["CREATETIMEEnd"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLEID"]))
            {
                sql.Append(" and CREATEPEOPLEID = '" + Request.QueryString["CREATEPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLE"]))
            {
                sql.Append(" and CREATEPEOPLE like '%" + Request.QueryString["CREATEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLEID"]))
            {
                sql.Append(" and LASTMODIFYPEOPLEID = '" + Request.QueryString["LASTMODIFYPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLE"]))
            {
                sql.Append(" and LASTMODIFYPEOPLE like '%" + Request.QueryString["LASTMODIFYPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMARK"]))
            {
                sql.Append(" and REMARK like '%" + Request.QueryString["REMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONID"]))
            {
                sql.Append(" and BUSINESSDIVISIONID = '" + Request.QueryString["BUSINESSDIVISIONID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONNAME"]))
            {
                sql.Append(" and BUSINESSDIVISIONNAME like '%" + Request.QueryString["BUSINESSDIVISIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONCODE"]))
            {
                sql.Append(" and BUSINESSDIVISIONCODE like '%" + Request.QueryString["BUSINESSDIVISIONCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYTIMEBegin"]))
            {
                sql.Append(" and  " + bll._dal.GetBeginDateString("LASTMODIFYTIME", Request.QueryString["LASTMODIFYTIMEBegin"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYTIMEEnd"]))
            {
                sql.Append(" and  " + bll._dal.GetEndDateString("LASTMODIFYTIME", Request.QueryString["LASTMODIFYTIMEEnd"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERCODE"]))
            {
                sql.Append(" and CUSTOMERCODE like '%" + Request.QueryString["CUSTOMERCODE"] + "%'");
            }

            if (!String.IsNullOrEmpty(Request.QueryString["TODOREMINDERTIMEBegin"]))
            {
                sql.Append(" and TODOREMINDERTIME >= '" + Request.QueryString["TODOREMINDERTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TODOREMINDERTIMEEnd"]))
            {
                sql.Append(" and TODOREMINDERTIME < '" + Request.QueryString["TODOREMINDERTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMINDERNUMBER"]))
            {
                sql.Append(" and REMINDERNUMBER like '%" + Request.QueryString["REMINDERNUMBER"] + "%'");
            }

            if (!String.IsNullOrEmpty(Request.QueryString["ENGINENUMBER"]))
            {
                sql.Append(" and ENGINENUMBER like '%" + Request.QueryString["ENGINENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEALERCODE"]))
            {
                sql.Append(" and DEALERCODE like '%" + Request.QueryString["DEALERCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEALERNAME"]))
            {
                sql.Append(" and DEALERNAME like '%" + Request.QueryString["DEALERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATIONCODE"]))
            {
                sql.Append(" and STATIONCODE like '%" + Request.QueryString["STATIONCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATIONNAME"]))
            {
                sql.Append(" and STATIONNAME like '%" + Request.QueryString["STATIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSMOBILEPHONE"]))
            {
                sql.Append(" and OWNERSMOBILEPHONE like '%" + Request.QueryString["OWNERSMOBILEPHONE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSOFFICEPHONE"]))
            {
                sql.Append(" and OWNERSOFFICEPHONE like '%" + Request.QueryString["OWNERSOFFICEPHONE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSHOMEPHONE"]))
            {
                sql.Append(" and OWNERSHOMEPHONE like '%" + Request.QueryString["OWNERSHOMEPHONE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSPEOPLE"]))
            {
                sql.Append(" and OWNERSPEOPLE like '%" + Request.QueryString["OWNERSPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSPEOPLECODE"]))
            {
                sql.Append(" and OWNERSPEOPLECODE like '%" + Request.QueryString["OWNERSPEOPLECODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SMSSTATUS"]))
            {
                sql.Append(" and SMSSTATUS like '%" + Request.QueryString["SMSSTATUS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VCOUNTRY"]))
            {
                sql.Append(" and VCOUNTRY like '%" + Request.QueryString["VCOUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VPROVINCE"]))
            {
                sql.Append(" and VPROVINCE like '%" + Request.QueryString["VPROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VPREFECTURECITY"]))
            {
                sql.Append(" and VPREFECTURECITY like '%" + Request.QueryString["VPREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VCITY"]))
            {
                sql.Append(" and VCITY like '%" + Request.QueryString["VCITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VVILLAGETOWN"]))
            {
                sql.Append(" and VVILLAGETOWN like '%" + Request.QueryString["VVILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VVILLAGE"]))
            {
                sql.Append(" and VVILLAGE like '%" + Request.QueryString["VVILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VGROUPTEAM"]))
            {
                sql.Append(" and VGROUPTEAM like '%" + Request.QueryString["VGROUPTEAM"] + "%'");
            }

            if (!String.IsNullOrEmpty(Request.QueryString["Extended"]))
            {
                string caseStatus = workOrderStatusBll.GetSessionStatusConditions(this.Page, ((int)WorkOrderType.投诉工单).ToString(), StatusType.中间节点);
                switch ((CaseExtended)Enum.Parse(typeof(CaseExtended), PageHelper.GetQueryString(this.Page, "Extended")))
                {
                    case CaseExtended.否:
                        {
                            sql.Append(String.Format(" and ( Status not in ({0}) Or ToDoReminderTime is null  Or (Status in ({0}) and ToDoReminderTime is not null and ToDoReminderTime >= sysdate) ) ", caseStatus));
                        }
                        break;
                    case CaseExtended.是:
                        {
                            sql.Append(String.Format(" and Status in ({0}) and ToDoReminderTime is not null and ToDoReminderTime < sysdate ", caseStatus));
                        }
                        break;

                }
            }
            #endregion

            if (!UserLoginInfo.IsAdministrator())
            {
                sql.Append(" and BUSINESSDIVISIONCODE = '" + _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE.Trim() + "'");

                //sql.Append(caBll.GenerateContentAuthorityConditions(_userLoginInfo, "CREATEPEOPLEID"));

                switch (UserLoginInfo.GetCurrentUserType())
                {
                    case UserType.中心部门:
                        {
                        }
                        break;
                    case UserType.供应商:
                    case UserType.市场部:
                    case UserType.服务商:
                    case UserType.经销商:
                        {
                            sql.Append(String.Format(" and CREATEUSERTYPE = '{0}' ", _userLoginInfo.UserEntity.USERTYPE.Trim()));
                            sql.Append(String.Format(" and CREATEDEPARTMENTID = '{0}' ", _userLoginInfo.UserEntity.DEPARTMENTID));
                        }
                        break;
                }

            }

            return sql;

        }

        /// <summary>
        /// 页面数据绑定
        /// </summary>
        private void gvDataBinding()
        {
            #region 查询条件字符串
            StringBuilder sql = GenerationSQLString();
            #endregion

            List<T_CONSULTINGCASE_Entity> list;

            //获取总的记录条数
            gvList.RecordCount = (int)bll.GetCount(sql.ToString());

            list = bll.GetList(sql.ToString(), gvList.CurrentPageIndex * gvList.PageSize, gvList.PageSize, gvList.SortConditions);

            gvList.DataSource = list;
            gvList.DataKeyNames = new string[] { "CASEID", "ToDoReminderTime", "STATUS" };
            gvList.DataBind();

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string url = HttpContext.Current.Request.Url.AbsolutePath;
            PageHelper.GetControlToUrlQuery(this.Page, ref url);
            Response.Redirect(url);
        }

        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            string fileName = "ConsoltingCase";
            fileName += _userLoginInfo.UserEntity.LOGINNAME.ToUpper();
            if (UserLoginInfo.IsAdministrator())
            {
                PageHelper.ShowMessage(this.Page, "请不要用系统管理导出数据！");
                return;
            }

            int recordBegin = StringHelper.ToInt(txtRecordBegin.Text.Trim(), 0);
            if (recordBegin != 0)
            {
                recordBegin--;
            }
            int recordEnd = StringHelper.ToInt(txtRecordEnd.Text.Trim(), 0);
            if (recordEnd != 0)
            {
                recordEnd--;
            }
            int recordCount = recordEnd - recordBegin;
            if (recordCount >= StringHelper.ToInt(configBll.GetCacheValueByName(this.Page, "ExportMaxRows"), 10000))
            {
                PageHelper.ShowMessage("导出区间大于单次导出数！");
                return;
            }

            StringBuilder sql = GenerationSQLString();
            DataTable dataTable = bll.GetDataTable(sql.ToString(), recordBegin, recordCount, gvList.SortConditions);
            //StringBuilder sql = GenerationSQLString();
            //DataTable dataTable = bll.GetDataTable(sql.ToString(), gvList.SortConditions);

            List<NPOIExcelHelper.FieldInfo> fieldInfos = new List<NPOIExcelHelper.FieldInfo>();

            #region 导出数据列

            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CASEID", "工单编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CALLER", "来电号码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CALLED", "被叫号码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CALLID", "主叫标识"));
            //fieldInfos.Add(new NPOIExcelHelper.FieldInfo("RECORDCODE", "录音代码"));
            //fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CALLTYPE", "来电类型"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CUSTOMERID", "客户编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CUSTOMERNAME", "客户姓名"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("FIRSTCONTACTTEL", "首选联系号码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("ADDRESS", "详细地址"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("COUNTRY", "国家"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("PROVINCE", "省份"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("PREFECTURECITY", "地级市"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CITY", "区/县/市"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("VILLAGETOWN", "乡/镇/街道"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("VILLAGE", "村"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("GROUPTEAM", "组/队"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CONSULTINGTYPE", "咨询类型"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("VINCODE", "整机编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("BRAND", "品牌"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("VEHICLETYPE", "类型"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("PRODUCTCODE", "产品代码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("SERIES", "系列"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("MODELS", "机型"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("ENGINEMODEL", "发动机型号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("ENGINEMANUFACTURERS", "发动机厂家"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CONSULTINGCONTENT", "咨询内容"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("APPROACH", "处理方法"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("STATUS", "处理状态", workOrderStatusBll.GetList().ToDictionary(p => p.ORDERSTATUSID.ToString(), p => p.ORDERSTATUSNAME)));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("RESULTS", "处理结果"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("REMINDERTIME", "待办提醒时间"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CREATETIME", "创建时间"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CREATEPEOPLEID", "创建人编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CREATEPEOPLE", "创建人"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("LASTMODIFYPEOPLEID", "最后修改人编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("LASTMODIFYPEOPLE", "最后修改人"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("REMARK", "备注"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("BUSINESSDIVISIONID", "事业部编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("BUSINESSDIVISIONNAME", "事业部名称"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("BUSINESSDIVISIONCODE", "事业部代码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("LASTMODIFYTIME", "最后修改时间"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CUSTOMERCODE", "客户代码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("TODOREMINDERTIME", "待办提醒时间"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("REMINDERNUMBER", "提醒次数"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("ENGINENUMBER", "发动机编号"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("DEALERCODE", "经销商代码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("DEALERNAME", "经销商名称"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("STATIONCODE", "服务商代码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("STATIONNAME", "服务商名称"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("OWNERSMOBILEPHONE", "车主手机"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("OWNERSOFFICEPHONE", "车主办公电话"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("OWNERSHOMEPHONE", "车主家庭电话"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("OWNERSPEOPLE", "车主姓名"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("OWNERSPEOPLECODE", "车主代码"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("SMSSTATUS", "短信状态"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CUSTOMERBASE", "客户群"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CUSTOMERTYPE", "客户类型"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("CUSTOMERLEVEL", "客户等级"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("BIGCUSTOMERTYPE", "大客户类型"));
            fieldInfos.Add(new NPOIExcelHelper.FieldInfo("IDNUMBER", "证件号码"));




            #endregion
            NPOIExcelHelper.MemoryStreamMaxRows = StringHelper.ToInt(configBll.GetCacheValueByName(this.Page, "MemoryStreamMaxRows"), 0);
            fileName = NPOIExcelHelper.DataTableToExcel(dataTable, fieldInfos, fileName + ".xls");
            UserLoginInfo.WriteLog(LogType.导出, "咨询工单导出", "咨询工单管理", fileName);
            dataTable.Clear();
            dataTable = null;
            GC.Collect();
        }

        #region GridView 事件
        /// <summary>
        /// GridView 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            T_CONSULTINGCASE_Entity entity = new T_CONSULTINGCASE_Entity();
            entity.CASEID = StringHelper.ToLong((sender as GridView).DataKeys[e.RowIndex].Values[0].ToString());

            long rel = bll.Delete(entity);
            if (rel > 0)
            {
                Response.Redirect(HttpContext.Current.Request.RawUrl);
            }
            else
            {

            }

        }

        /// <summary>
        /// GridView 行数据绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string temp = string.Empty;
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {
                        GridView gv = (sender as GridView);
                        for (int i = 0; i < gv.Columns.Count; i++)
                        {
                            TemplateField tf = gv.Columns[i] as TemplateField;
                            if (tf != null)
                            {
                                #region 存储值 转换成  显示值
                                switch (tf.HeaderText)
                                {
                                    case "操作":
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;
                                    default:
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;

                                }
                                #endregion
                            }

                            BoundField bf = gv.Columns[i] as BoundField;
                            if (bf != null)
                            {
                                #region 存储值 转换成  显示值
                                switch (bf.DataField)
                                {
                                    case "CONSULTINGTYPE":
                                        {
                                            temp = e.Row.Cells[i].Text.Trim();
                                            temp = dBll.GetCacheValueByTypeKey(this.Page, "ConsultingType", temp);
                                            e.Row.Cells[i].Text = temp;
                                        }
                                        break;
                                    case "STATUS":
                                        {
                                            temp = e.Row.Cells[i].Text.Trim();
                                            T_WORKORDERSTATUS_Entity entity =
                                                workOrderStatusBll.GetPageItem_T_WORKORDERSTATUS_EntityByKey(this.Page, StringHelper.ToInt(temp, 0));
                                            if (entity != null)
                                            {
                                                temp = entity.ORDERSTATUSNAME;
                                                if (!String.IsNullOrEmpty(entity.RECORDSTYLE))
                                                {
                                                    e.Row.Attributes["style"] = entity.RECORDSTYLE;

                                                }
                                            }
                                            e.Row.Cells[i].Text = temp;
                                        }
                                        break;
                                    default:
                                        {

                                        }
                                        break;
                                }
                                #endregion
                            }
                        }
                        #region 超期样式
                        DateTime dt = DateTime.Now;
                        temp = (gv.DataKeys[e.Row.RowIndex].Values["ToDoReminderTime"] == null) ? "" : gv.DataKeys[e.Row.RowIndex].Values["ToDoReminderTime"].ToString();
                        string status = (gv.DataKeys[e.Row.RowIndex].Values["STATUS"] == null) ? "" : gv.DataKeys[e.Row.RowIndex].Values["STATUS"].ToString();
                        if (DateTime.TryParse(temp, out dt))
                        {
                            if (dt.CompareTo(DateTime.Now) < 0)
                            {
                                try
                                {
                                    if (workOrderStatusBll.GetSessionStatusType(this.Page, status) == StatusType.中间节点)
                                    {
                                        e.Row.Attributes["style"] = configBll.GetCacheValueByName(this.Page, "ExtendedStyle");
                                    }
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        #endregion
                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }

        /// <summary>
        /// GridView 行创建事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowCreated(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {

                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }
        #endregion
		
    }
}
